package team.seekers.hula.course.resource.examSubmit.entity.dao;

import com.baomidou.mybatisplus.annotation.*;
import lombok.*;
import org.springframework.beans.BeanUtils;
import team.seekers.hula.common.entity.BaseDO;
import team.seekers.hula.course.resource.examSubmit.entity.dto.ExamRecordCreateDTO;
import team.seekers.hula.course.resource.examSubmit.entity.dto.ExamRecordDTO;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * (EduExamRecord)实体类
 *
 * @author GH
 * @since 2022-05-09 10:41:01
 */
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@EqualsAndHashCode(callSuper = true)
@TableName(ExamRecordDOField.TABLE_NAME)
public class ExamRecordDO extends BaseDO {

    private static final long serialVersionUID = 1L;

    @TableId(value = ExamRecordDOField.ID, type = IdType.ASSIGN_ID)
    private String id;
    /**
     * 测试id
     */
    @TableField(ExamRecordDOField.EXAM_ID)
    private String examId;
    /**
     * 用户id
     */
    @TableField(ExamRecordDOField.USER_ID)
    private String userId;
    /**
     * 测试分数
     */
    @TableField(ExamRecordDOField.SCORE)
    private Float score;
    /**
     * 提交信息集合
     */
    @TableField(ExamRecordDOField.SUBMISSIONS)
    private byte[] submissions;
    /**
     * 测试状态
     */
    @TableField(ExamRecordDOField.STATUS)
    private Integer status;
    /**
     * 测试次数
     */
    @TableField(ExamRecordDOField.COUNT)
    private Integer count;

    @TableField(ExamRecordDOField.DELETED)
    @TableLogic(value = "0", delval = "1")
    private Integer deleted;

    @TableField(value = ExamRecordDOField.GMT_CREATE, fill = FieldFill.INSERT)
    private Date gmtCreate;

    @TableField(value = ExamRecordDOField.GMT_MODIFIED, fill = FieldFill.INSERT_UPDATE)
    private Date gmtModified;

    public static List<ExamRecordDTO> toDTOList(List<ExamRecordDO> examRecordDOList){
        ArrayList<ExamRecordDTO> examRecordDTOS = new ArrayList<>();
        for (ExamRecordDO examRecordDO : examRecordDOList) {
            ExamRecordDTO examRecordDTO = new ExamRecordDTO();
            BeanUtils.copyProperties(examRecordDO,examRecordDTO);
            examRecordDTOS.add(examRecordDTO);
        }
        return examRecordDTOS;
    }
}
